你正在 VB 加油站!

最近更新

加油站台

下载区域

文档资料收集

写流言

瞧瞧流言

友情连接

写信给俺啦

 

C 用户界面

B 窗口

008 禁止使用 Alt+F4 关闭窗口 98-8-21

Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Private Const MF_BYPOSITION = &H400&

Private Sub Form_Load()
Dim hwndMenu As Long
Dim c As Long
hwndMenu = GetSystemMenu(Me.hwnd, 0)

c = GetMenuItemCount(hwndMenu)
'slet det nederste menupunkt ("LUK ALT+F4")

DeleteMenu hwndMenu, c - 1, MF_BYPOSITION

c = GetMenuItemCount(hwndMenu)
'slet det nederste menupunkt ("Skillelinje")
DeleteMenu hwndMenu, c - 1, MF_BYPOSITION

End Sub到页首

007 窗口事件的发生顺序 98-8-03

1 Form_Initialize
2 Form_Load
3 Form_Resize
4 Form_Activate
5 Form_GotFocus
6 Form_Paint
7 Form_Unload
8 Form_Terminate到页首

006 一闪而过的应用启动窗口 98-7-15

类似于 VB 的一闪而过的应用启动窗口,利用以下的方法实现:
1 在应用启动窗口中使用 Timer,例如记数到 2 秒时,自动关闭窗口。
2 在主程序启动时,先 Show 应用启动窗口(不要用参数)。设置应用启动窗口保持在最前面。继续其他的工作。到页首

005 在 Unload Me 后面的语句可能引起 Form 行为异常 98-7-13

一个偶然的机会,我在 Command1 的 Click 中使用了以下的语句:

if Command1.caption = "a"  then
...
unload me
end if
if Command1.caption = "b" then
....
end if

结果在Command1 为 a 时,我的 Form_Load 里的变量不能正确初始化,调试的结果是在执行了 unload me 后,在 if Command1.caption = "b" then 时,Form 又被Load 了,执行了 Form_Load。而在下次 Form.Show 时,不再执行 Form_Load 。

所以,好的方法是不要在 unload me 后执行其他语句。到页首

004 透明的窗口 98-7-04

声明:
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Const WS_EX_TRANSPARENT = &H20&
Const GWL_EXSTYLE = (-20)
使用:
retval = SetWindowLong(Form2.hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT)
透明效果是出来啦,如果移动的话,屏幕会变乱。到页首

003 使窗口保持在最前面

Declare Function SetWindowPos Lib "user32" ( ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2

public sub SetFormOnTop(myForm as object)
SetWindowPos myForm.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE
end sub到页首

002 制作窗口背景

现有图片 Picture, 用以下的方法,将该图片布满整个窗口:
For I = 0 To ScaleWidth \ Picture.Width
  For J = 0 To ScaleHeight \ Picture.Height
    PaintPicture Picture, I * Picture.Width, J * Picture.Height
Next
Next
到页首

001 创建不规则窗口

Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long

Private Sub Form_Load()
Show
SetWindowRgn hWnd,   CreateEllipticRgn(0, 0, 300, 200),   True
End Sub
上述代码可以创建一个椭圆形状的窗口。 到页首

 

知/的/更/多 做/的/更/好